//定义store
import { defineStore } from 'pinia'
import { ref } from 'vue'
import { sellerLoginAPI, newSellerInfoAPI } from '@/apis/seller'

export const useSellerStore = defineStore('seller', () => {
    //有点像javaBean
    //1.定义属性
    //2.定义属性的方法
    //3.决定暴露出去的接口
    //导航列表的数据管理
    //state 导航列表数据
    const sellerInfo = ref({})


    //action获取导航数据的方法


    const getSellerInfo = async ({ username, password }) => {
        const res = await sellerLoginAPI({ username, password })
        console.log(res);
        sellerInfo.value = res.data;
    }

    const getNewSellerInfo = async () => {
        const res = await newSellerInfoAPI()
        console.log(res);
        sellerInfo.value.data.user = res.data.data
    }

    const clearSellerInfo = async () => {
        sellerInfo.value = {}
    }
    return {
        sellerInfo,
        clearSellerInfo,
        getSellerInfo,
        getNewSellerInfo
    }
}, {
    persist: true//持久化存储
})